﻿#region 참조 네임스페이스

using Skying;
using Skying.Runtime.Serialization.Formatters.Json;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Windows.Forms;
using System.Xml;

#endregion

namespace JsonConverter
{
	[DataContract]
	class Person
	{
		[DataMember]
		internal string Name
		{
			get;
			set;
		}

		[DataMember]
		internal int Age
		{
			get;
			set;
		}
	}

	public partial class MainForm : Form
	{
		#region 생성자/소멸자

		public MainForm()
		{
			this.InitializeComponent();
		}

		#endregion

		#region 버튼 이벤트

		/// <summary>
		/// ToObject 버튼이 클릭됐을 때 발생하는 이벤트를 구현한다.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ToObjectButton_Click(object sender, EventArgs e)
		{
			using (FileStream stream = new FileStream(@"C:\test.json", FileMode.Create, FileAccess.Write))
			{
				DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Person));

				Person person = new Person() { Age = 12, Name = "Ammy" };

				serializer.WriteObject(stream, person);

				stream.Flush();
			}


			//string result = StringExtensions.EscapeString(this.JsonTextBox.Text);

			//Console.WriteLine(result.Contains("\\\""));

			//JsonObjectCollection json = JsonFormatter.Deserialize(this.JsonTextBox.Text);

			//Console.WriteLine(json.ToString());
		}

		/// <summary>
		/// ToText 버튼이 클릭됐을 때 발생하는 이벤트를 구현한다.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ToTextButton_Click(object sender, EventArgs e)
		{

		}

		#endregion
	}
}
